{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "22084315",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入：刘亦菲\n",
      "<!DOCTYPE html>\n",
      "<html lang=\"zh-CN\">\n",
      "<head>\n",
      "    <meta charset=\"utf-8\">\n",
      "    <title>ç¾åº¦å®å",
      "¨éªè¯</title>\n",
      "    <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n",
      "    <meta name=\"apple-mobile-web-app-capable\" content=\"yes\">\n",
      "    <meta name=\"apple-mobile-web-app-status-bar-style\" content=\"black\">\n",
      "    <meta name=\"viewport\" content=\"width=device-width, user-scalable=no, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0\">\n",
      "    <meta name=\"format-detection\" content=\"telephone=no, email=no\">\n",
      "    <link rel=\"shortcut icon\" href=\"https://www.baidu.com/favicon.ico\" type=\"image/x-icon\">\n",
      "    <link rel=\"icon\" sizes=\"any\" mask href=\"https://www.baidu.com/img/baidu.svg\">\n",
      "    <meta http-equiv=\"X-UA-Compatible\" content=\"IE=Edge\">\n",
      "    <meta http-equiv=\"Content-Security-Policy\" content=\"upgrade-insecure-requests\">\n",
      "    <link rel=\"stylesheet\" href=\"https://ppui-static-wap.cdn.bcebos.com/static/touch/css/api/mkdjump_aac6df1.css\" />\n",
      "</head>\n",
      "<body>\n",
      "    <div class=\"timeout hide-callback\">\n",
      "        <div class=\"timeout-img\"></div>\n",
      "        <div class=\"timeout-title\">ç½ç»ä¸ç»åï¼è¯·ç¨åéè¯</div>\n",
      "        <button type=\"button\" class=\"timeout-button\">è¿åé¦é¡µ</button>\n",
      "    </div>\n",
      "    <div class=\"timeout-feedback hide-callback\">\n",
      "        <div class=\"timeout-feedback-icon\"></div>\n",
      "        <p class=\"timeout-feedback-title\">é®é¢åé¦</p>\n",
      "    </div>\n",
      "\n",
      "<script src=\"https://ppui-static-wap.cdn.bcebos.com/static/touch/js/mkdjump_v2_21d1ae1.js\"></script>\n",
      "</body>\n",
      "</html>\n",
      "\n",
      "已下载。。。刘亦菲\n"
     ]
    }
   ],
   "source": [
    "import requests\n",
    "# 01 获取数据\n",
    "keyword = input(\"请输入：\")\n",
    "url = f\"https://www.baidu.com/s?tn=50000021_hao_pg&ie=utf-8&word={keyword}\"\n",
    "header = {\"User-Agent\":\"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36\", \"Cookie\":\"BIDUPSID=204963D75E9405D8B4FD03BED7DEE0A9; PSTM=1699635195; BAIDUID=204963D75E9405D864D662AE365BEFF5:FG=1; BAIDUID_BFESS=204963D75E9405D864D662AE365BEFF5:FG=1; ZFY=HeJsolEAi1iHcpMmtMqtjfozhg6NVXuDQmkEbR89vmQ:C; H_PS_PSSID=39671_39664_39687_39695_39676_39678_39713_39740; delPer=0; PSINO=7; BA_HECTOR=0g2k0085008h2g2020ahag821il7cgr1r; BDORZ=B490B5EBF6F3CD402E515D22BCDA1598; BDRCVFR[PaHiFN6tims]=mk3SLVN4HKm\"}\n",
    "# 02 解析数据\n",
    "response = requests.get(url, headers=header)\n",
    "# 03 提取数据\n",
    "print(response.text)\n",
    "# 04 存储数据\n",
    "with open(keyword + '.html', 'w', encoding='utf-8') as f:\n",
    "    f.write(response.text)\n",
    "    print(f'已下载。。。{keyword}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "03af12e5",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
